"""
临时文件清理脚本
手动清理所有临时文件
"""

import sys
from pathlib import Path

project_root = Path(__file__).parent
sys.path.insert(0, str(project_root))

from src.utils.temp_file_manager import get_temp_file_manager


def main():
    """主函数"""
    print("=" * 60)
    print("临时文件清理工具")
    print("=" * 60)
    
    manager = get_temp_file_manager()
    
    # 显示当前统计
    print("\n当前临时文件统计:")
    stats = manager.get_temp_file_stats()
    
    print(f"\n总文件数: {stats['total_files']}")
    print(f"总大小: {stats['total_size'] / 1024:.2f} KB")
    
    if stats['total_files'] > 0:
        print("\n各类别详情:")
        for category, info in stats['categories'].items():
            if info['files'] > 0:
                print(f"  {category}: {info['files']} 个文件, {info['size'] / 1024:.2f} KB")
        
        # 确认清理
        choice = input("\n是否清理所有临时文件? (y/n): ").strip().lower()
        
        if choice == 'y':
            manager.cleanup_all()
            
            # 显示清理后的统计
            new_stats = manager.get_temp_file_stats()
            print(f"\n清理完成!")
            print(f"剩余文件: {new_stats['total_files']}")
        else:
            print("取消清理")
    else:
        print("\n✓ 没有需要清理的临时文件")
    
    print("\n" + "=" * 60)


if __name__ == "__main__":
    main()
